#!/usr/bin/perl
#Author: Jeff Bean
#Apache Log Project part 3

$log = $ARGV[0];
%match = ();

open FILE, "<", $log or die "log not found";
while (<FILE>) {
        $_ =~ /"CONNECT.+?"/;
        $line = $&;
        chomp $line;
        $match{$line} += 1;
}
close FILE;

$count = 0;
foreach $value ( sort { $match{$b} <=> $match{$a} } keys %match) {
        $count += 1;
        print "$count $match{$value} $value\n";
        if ( $count == 10 ) {
                last;
        }
}
